//获取应用实例
var app = getApp();
Page({
    data: {
        addressList: []
    },
    //选中谁就把谁设置为默认的
    selectTap: function (e) {
        const that = this;
        wx.request({
            url: app.buildUrl("/my/address/ops"),
            header: app.getRequestHeader(),
            method: 'POST',
            data: {
                id: e.currentTarget.dataset.id,
                act: 'default'
            },
            success: function (res) {
                const resp = res.data;
                if (resp.code === 200) {
                    that.setData({
                       list:resp.data.list
                    });
                } else {
                    app.alert({"content": resp.msg});
                    return;
                }
            }
        })
        //从商品详情下单选择地址之后返回
        wx.navigateBack({});
    },
    addessSet: function (e) {
        wx.navigateTo({
            url: "/pages/my/addressSet?id=" + e.currentTarget.dataset.id
        })
    },
    onShow: function () {
        var that = this;
        that.getList();
    },
    getList: function () {
        const that = this;
        wx.request({
            url: app.buildUrl('/my/address/index'),
            header: app.getRequestHeader(),
            success: function (res) {
                const result = res.data;
                if (result.code === 200) {
                    that.setData({
                       addressList:result.data.list
                    });
                } else {
                    app.alert({"content": result.msg});
                    return;
                }
            }
        })
    }
});
